%::PROVIDES=(
	name	=> ["CHECK_NBD"],
	desc	=> ["Check Netblock Block status"],
	type	=> "request",
	code	=> \&::do_handle_checknbd
);

sub ::do_handle_checknbd {
my $args=shift;
my ($app,$h,$r,$cmd);
my $cmdname=$args->{"_CMDNAME"};
my ($ref,$l,$c,$fsinfo);

	if(!exists($args->{APP})) {
		logwarn("$cmdname request missing APP argument");
		return "MISSING_ARG";
	}
	$app=$args->{APP};


	$fsinfo=new fsmap(FILE => "/etc/cluster/.resources/fsmap/$app",
				APPLICATION => $app, DATADETAIL => "drbd");
	if(!defined($fsinfo)) {
		logwarn("Unable to get fsmap details for $app!");
		return "ERROR";
	}
	#########################################################
	# we get details for every known entry ... and check	#
	# we have device configuration ... and that is all.	#
	#########################################################
	$c=$fsinfo->count;
	$l=0;
	while($l<$c) {
		$ref=$fsinfo->get_sync_state(RECNO => $l);
		if(!defined($ref)) {
			return "NOT_OK";
		}
		@l2=split(/:/,$ref);
		if($l2[3] eq "inactive") {
			return "NOT_OK";
		}
		if($l2[3] eq "standalone") {
			return "NO_REMOTE";
		}
		$l++;
	}
	return "OK";
}

1;
